<?php
require_once('include/GeneralTop.php');
require('include/class/db.php');
$db = new db;
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>上海小动物保护分会(SSAPA)</title>
<link href="Felix_css.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
if(isset($_POST['submit'])) {
	$sql = "select * from member_info where Email_account='".$_POST['addr']."'";
	$query = $db->query($sql);
	if(0 < $db->num($query)) {
		$new_pass = uniqid();
		$new_pass_token = md5($new_pass);
		$update = "update member_info set pass_reclaim_bak='".$new_pass_token."' where Email_account='".$_POST['addr']."'";
		$db->query($update);
    	$subject = 'You New Password(SSAPA)';
    	$message = 'You new password is '.$new_pass.'. Please copy following URL to browser to reset password.
'.WEBSITE_HOST.'/resetPass.php?token='.$new_pass_token.'
After the reset, you can sign in with the new password.';
    	mail($_POST['addr'], $subject, $message);
    	$msg = MSG_RECLAIM_PASS_SUC;
	}
	else {
		$msg = MSG_RECLAIM_PASS_ERROR;
	}
?>
<div width="360" align="center" class="font_12px_gray_high">
<?php echo $msg?>
<br><br>
<input type="button" name="close" id="submit" value=" <?php echo TEXT_CLOSE?> " onclick="parent.tb_remove();">
</div>
<?php
}
else {
?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" onsubmit="return check_form();">
<div width="360" align="center" class="font_12px_gray_high">
<?php echo MSG_RECLAIM_PASS?>
<br><br>
<?php echo TEXT_EMAIL?>: <input type="text" name="addr" id="addr" size="50">
<br><br>
<input type="submit" name="submit" id="submit" value=" <?php echo TEXT_SUBMIT?> ">
</div>
</form>
<?php
}
?>
</body>
</html>
<script>
function check_form(){
	if (document.getElementById('addr').value == '') {
		alert('请输入邮件地址');
		document.getElementById('addr').focus();
		return false;
	}
	return true;
}
</script>